package kr.saeildamil.androidstudy.ch14;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NumEditWidget extends LinearLayout implements TextWatcher {
	
	EditText mEdit;
	TextView mText;
	
	public NumEditWidget(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public NumEditWidget(Context context) {
		super(context);
		init();
	}
	
	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		mText.setText("Now Length : " + s.length() + " Characters");
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
	}
	
	@Override
	public void afterTextChanged(Editable arg0) {
		
	}

	private void init() {
		setOrientation(LinearLayout.VERTICAL);
		mEdit = new EditText(getContext());
		mText = new TextView(getContext());
		
		mText.setText("Now Length : 0 Characters" );
		
		LinearLayout.LayoutParams param = new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		addView(mEdit,param);
		addView(mText, param);
		
		mEdit.addTextChangedListener(this);
	}

}
